package com.pfzy.ui.activity.pick;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.pfzy.ui.R;
import com.pfzy.ui.log.MyLog;
import com.pfzy.ui.view.pickertime.WheelView2;

import java.util.ArrayList;
import java.util.List;

public class PickerDlg extends Dialog implements View.OnClickListener {
    List<String> hours = new ArrayList();
    List<String> minutes = new ArrayList();

    public PickerDlg(@NonNull Context context) {
        super(context);
        initWindow();
        initData();
        initView();
    }

    private void initWindow() {
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(layoutParams);
        getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
        getWindow().setGravity(Gravity.CENTER);
        setCancelable(false);
    }

    private void initData() {
        for (int i = 0; i < 24; i++) {
            if (i < 10) {
                hours.add("0" + i + "时");
            } else {
                hours.add(i + "时");
            }
        }

        for (int i = 0; i < 60; i++) {
            if (i < 10) {
                minutes.add("0" + i + "分");
            } else {
                minutes.add(i + "分");
            }
        }
    }

    private void initView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dlg_picker, null, false);
        ImageView closeBtn = view.findViewById(R.id.dlg_picker_cloe);
        closeBtn.setOnClickListener(this);
        Button btn = view.findViewById(R.id.dlg_picker_end_btn);
        btn.setOnClickListener(this);

        WheelView2 startHourView = view.findViewById(R.id.dlg_picker_start_hour);
        startHourView.setData(hours);

        WheelView2 startMinute = view.findViewById(R.id.dlg_picker_start_minute);
        startMinute.setData(minutes);

        WheelView2 endHour = view.findViewById(R.id.dlg_picker_end_hour);
        endHour.setData(hours);

        WheelView2 endMinute = view.findViewById(R.id.dlg_picker_end_minute);
        endMinute.setData(minutes);

        setContentView(view);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dlg_picker_cloe:
                dismiss();
                break;
            case R.id.dlg_picker_end_btn:
                dismiss();
                break;
            default:
                break;
        }
    }

    private void _logd(String msg) {
        MyLog.logd("时钟选择器1 : " + msg);
    }
}
